package constant.milk.periodapp.dialog;


import java.util.Calendar;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import constant.milk.periodapp.R;

public class MilkMonthDialog extends Dialog
{
	private View contentView;
	
	private TextView preTextView;
	private TextView nextTextView;
	private TextView yearTextView;
	
	private TextView month1TexTiew;
	private TextView month2TexTiew;
	private TextView month3TexTiew;
	private TextView month4TexTiew;
	private TextView month5TexTiew;
	private TextView month6TexTiew;
	private TextView month7TexTiew;
	private TextView month8TexTiew;
	private TextView month9TexTiew;
	private TextView month10TexTiew;
	private TextView month11TexTiew;
	private TextView month12TexTiew;
	
	private DateCallBank callbank = null;
	
	private Calendar cal;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.dialog_month);
		
		setFindView();
		setOnClick();
		setData();
	}

	private void setFindView()
	{
		contentView = findViewById(R.id.dialogMonthContentView);
		
		preTextView = (TextView) findViewById(R.id.dialogDatePreTextView);
		nextTextView = (TextView) findViewById(R.id.dialogDateNextTextView);
		yearTextView = (TextView) findViewById(R.id.dialogDateYearTextView);
		
		month1TexTiew = (TextView) findViewById(R.id.dialogDate1MonthTextView);
		month2TexTiew = (TextView) findViewById(R.id.dialogDate2MonthTextView);
		month3TexTiew = (TextView) findViewById(R.id.dialogDate3MonthTextView);
		month4TexTiew = (TextView) findViewById(R.id.dialogDate4MonthTextView);
		month5TexTiew = (TextView) findViewById(R.id.dialogDate5MonthTextView);
		month6TexTiew = (TextView) findViewById(R.id.dialogDate6MonthTextView);
		month7TexTiew = (TextView) findViewById(R.id.dialogDate7MonthTextView);
		month8TexTiew = (TextView) findViewById(R.id.dialogDate8MonthTextView);
		month9TexTiew = (TextView) findViewById(R.id.dialogDate9MonthTextView);
		month10TexTiew = (TextView) findViewById(R.id.dialogDate10MonthTextView);
		month11TexTiew = (TextView) findViewById(R.id.dialogDate11MonthTextView);
		month12TexTiew = (TextView) findViewById(R.id.dialogDate12MonthTextView);
	}
	
	private void setOnClick()
	{
		contentView.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View v)
			{	
				dismiss();
			}
		});
		
		preTextView.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				cal.add(Calendar.YEAR, -1);
				setYear();
			}
		});
		
		nextTextView.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				cal.add(Calendar.YEAR, 1);
				setYear();
			}
		});
		
		month1TexTiew.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				callbank.getDate(cal.get(Calendar.YEAR), 0);
				dismiss();
			}
		});
		
		month2TexTiew.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				callbank.getDate(cal.get(Calendar.YEAR), 1);
				dismiss();
			}
		});
		
		month3TexTiew.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				callbank.getDate(cal.get(Calendar.YEAR), 2);
				dismiss();
			}
		});
		
		month4TexTiew.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				callbank.getDate(cal.get(Calendar.YEAR), 3);
				dismiss();
			}
		});
		
		month5TexTiew.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				callbank.getDate(cal.get(Calendar.YEAR),4);
				dismiss();
			}
		});
		
		month6TexTiew.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				callbank.getDate(cal.get(Calendar.YEAR), 5);
				dismiss();
			}
		});
		
		month7TexTiew.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				callbank.getDate(cal.get(Calendar.YEAR), 6);
				dismiss();
			}
		});
		
		month8TexTiew.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				callbank.getDate(cal.get(Calendar.YEAR), 7);
				dismiss();
			}
		});
		
		month9TexTiew.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				callbank.getDate(cal.get(Calendar.YEAR), 8);
				dismiss();
			}
		});
		
		month10TexTiew.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				callbank.getDate(cal.get(Calendar.YEAR), 9);
				dismiss();
			}
		});
		
		month11TexTiew.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				callbank.getDate(cal.get(Calendar.YEAR), 10);
				dismiss();
			}
		});
		
		month12TexTiew.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				callbank.getDate(cal.get(Calendar.YEAR), 11);
				dismiss();
			}
		});
	}
	
	private void setData()
	{
		setYear();
	}

	public MilkMonthDialog(Context context, DateCallBank callbank, int year)
	{
		super(context, android.R.style.Theme_Translucent_NoTitleBar);
		
		this.callbank = callbank;
		
		cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, year);
	}
	
	private void setYear()
	{
		yearTextView.setText(cal.get(Calendar.YEAR) + "");
	}
	
	public interface DateCallBank
	{
		public abstract void getDate(int year, int month);
	}
}
